<template>
	<div class="serial-num">
		<div>
			<label>{{$t('route.base')}}</label>
			<div></div>
			<button><img /><label>{{$t('route.Serial')}}</label></button>
		</div>

		<div>
			<div>

				<div class="div-handle-right">
					<!-- 	<el-button>删除</el-button>
					<el-button @click='jumpPage(0)'>添加</el-button> -->
					<el-button @click='dialogVisible = true'>{{$t('route.BatchAdd')}}</el-button>
				</div>
			</div>

			<el-table class="table" :data="snBatchList" style="width: 100%">
				<el-table-column prop="adminName" :label="$t('route.Customer')" />
				<el-table-column prop="startSn" :label="$t('route.Initial_sequence_number')" />
				<el-table-column prop="typeNum" :label="$t('route.Equipment_model')" />
				<el-table-column prop="count" :label="$t('route.amount')" />
				<el-table-column :label="$t('route.time')">
					<template #default="scope">
						{{new Date(scope.row.gmtCreate).format('yyyy-MM-dd hh:mm:ss')}}
					</template>
				</el-table-column>
				<el-table-column :label="$t('route.operate')">
					<template #default="scope">
						<el-button type="text" @click="downloadClick(scope.row)">{{$t('route.download')}}</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination style="float: right;" background @current-change="handlePageChange" :current-page="query.pageNum"
					:page-size="query.pageSize" layout="total, prev, pager, next" :total="query.total"></el-pagination>
			</div>
		</div>


		<!-- 编辑弹出框 -->
		<el-dialog :title="$t('route.Batch_generated_sequence_number')" v-model="dialogVisible">
			<el-form label-position="right" label-width="120px">
				<el-form-item :label="$t('route.amount')">
					<el-input-number v-model="serialNumCount" :min="1" :max="10000" />
				</el-form-item>
				<el-form-item>
					<el-button @click='addClick'>{{$t('route.Add')}}</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>


	</div>
</template>

<script>
	import http from "../../js/http/http.js";
	import api from "../../js/http/api.js";
	import CommonUtils from "../../js/common/common-utils.js";
	import i18n from '../../i18n/index';
	export default {
		data() {
			return {
				query: {
					pageNum: 1,
					pageSize: 10,
					total: 0,
				},
				snBatchList: [],
				dialogVisible: false,
				serialNumCount: 1

			};
		},
		methods: {
			downloadClick(item) {
				this.download(api.BASE_URI + api.DOWN_LOAD_SN_BATCH + '?snBatchId=' + item.id, i18n.global.t('route.Serial') + new Date().format('yyyy-MM-dd') + '.txt')
			},
			download(url, fileName) {
				let x = new XMLHttpRequest();
				x.open("GET", url, true);
				x.responseType = 'blob';
				x.onload = function(e) {
					let url = window.URL.createObjectURL(x.response)
					let a = document.createElement('a');
					a.href = url
					a.download = fileName
					a.click()
				}
				x.send();
			},
			getSnBatchList() {
				http.post(api.GET_SN_BATCH_LIST, {
					pageNum: this.query.pageNum,
					pageSize: this.query.pageSize,
				}, data => {
					this.snBatchList = data.data.snBatchList;
					this.query.total = data.data.total;
				});
			},
			jumpPage(type) {
				if (type == 0 || type == 1) {
					this.$router.push('/add-station');
				}
			},
			handlePageChange(pageNum) {
				this.query.pageNum = pageNum;
				this.getSnBatchList();
			},
			addClick() {
				http.post(api.CREATE_SN_BATCH, {
					count: this.serialNumCount,
					adminId: -1
				}, data => {
					this.$message.success(i18n.global.t('route.Successfully_added'));
					this.getSnBatchList();
					this.dialogVisible = false;
				});
			}

		},
		created() {
			this.getSnBatchList();

		}
	};
</script>
<style lang="scss" scoped>
	.serial-num {
		color: #444444;
		font-size: 18px;
		padding-right: 20px;
		height: calc(100vh - 100px);
		// overflow: scroll;
		scrollbar-width: none;
		/* firefox */
		-ms-overflow-style: none;
		/* IE 10+ */
		overflow-x: hidden;
		overflow-y: auto;

		>div {
			display: flex;
			flex-direction: row;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;
		}

		>div:nth-of-type(1) {
			>label:nth-of-type(1) {
				font-weight: 600;
			}

			>div:nth-of-type(1) {
				width: 1px;
				background-color: #cccccc;
				height: 15px;
				margin: 0px 20px;
			}

			>button:nth-of-type(1) {
				background-image: url(../../assets/img/customer-1.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				padding: 5px 10px;
				border: 0px;
				display: flex;
				color: #ffffff;
				flex-direction: row;
				align-items: center;
				font-weight: 800;

				>img {
					margin-right: 7px;
					width: 15px;
					height: 15px;
					content: url(../../assets/img/customer-2.png);
				}

			}
		}

		>div:nth-of-type(2) {
			flex-direction: column;

			>div:nth-of-type(1) {
				display: flex;
				flex-direction: row;
				align-items: center;

				.div-handle-right {
					flex: 1;
					flex-direction: row-reverse;
					text-align: right;
					display: flex;
					align-items: center;

					>input:nth-of-type(1) {
						border: 1px solid #eeeeee;
						font-size: 15px;
						width: 150px;
						padding: 5px 8px;
						outline: none;
					}

					>button {
						color: #A866FF;
						margin-left: 10px;
						padding: 4px 20px;
					}
				}
			}

			.table {
				margin-top: 20px;
			}

		}
	}
</style>
